<!--
	作者：956911785@qq.com
	时间：2019年11月20日18:42:04
	描述：账号-添加
-->

<template>
	<Modal :title="title" v-model="modal0" width="700px">
		<Form ref="params" :model="params" :rules="ruleValidate" :label-width="100" label-position="left">
			<div style="width:100%;height:500px;">
				<div style="width:100%;height: 60px;line-height: 60px;float:left;">
					<FormItem prop="dlzh" label="登录账号">
						<Input v-model.trim="params.dlzh" placeholder="请输入登录账号" clearable style="width: 70%"></Input>
					</FormItem>
				</div>
				<div style="width:100%;height: 60px;line-height: 60px;float:left;">
					<FormItem  prop="name" label="姓名">
						<Input v-model.trim="params.name" placeholder="请输入姓名" clearable style="width: 70%"></Input>
					</FormItem>
				</div>
				
				<div style="width:100%;height: 60px;line-height: 60px;float:left;">
					<FormItem prop="wstate" label="账号类别">
						<Select v-model="params.wstate" style="width:70%;float:left;" clearable on-change="wstatechange">
							<Option value="">请选择</Option>
						    <Option value="1">学生</Option>
							<Option value="2">教师</Option>
						</Select>
					</FormItem>
				</div>
				
				<div style="width:100%;height: 60px;line-height: 60px;float:left;">
					<FormItem  prop="sex" label="性别">
						<Select v-model="params.sex" style="width:70%;float:left;" clearable>
							<Option value="">请选择</Option>
						    <Option value="男">男</Option>
							<Option value="女">女</Option>
						</Select>
					</FormItem>
				</div>

				<div style="width:100%;height: 60px;line-height: 60px;float:left;">
					<FormItem label="职位">
						<Input v-model.trim="params.zw" placeholder="多个职位请用逗号分隔" clearable style="width: 70%"></Input>
					</FormItem>
				</div>
				
				<div style="width:100%;height: 60px;line-height: 60px;float:left;">
					<FormItem prop="nj" label="年级">
						<Input v-model.trim="params.nj" type="number" placeholder="班主任与学生为必填项" clearable style="width: 70%"></Input>
					</FormItem>
				</div>
				
				<div style="width:100%;height: 60px;line-height: 60px;float:left;">
					<FormItem prop="bj" label="班级">
						<Input v-model.trim="params.bj" type="number" placeholder="班主任与学生为必填项" clearable style="width: 70%"></Input>
					</FormItem>
				</div>
				
				<div style="width:100%;height: 60px;line-height: 60px;float:left;">
					<FormItem prop="year" label="学生入学年">
						<Input v-model.trim="params.year" type="number" placeholder="学生为必填项" style="width: 70%"></Input>
					</FormItem>
				</div>
				
		   </div> 
	    </Form>
	   	<div slot="footer">
	    	<Button type="text"  @click="closeModal()">取消</Button>
	    	<Button type="primary" @click="addsave()" >确定</Button>
	    </div>
     </Modal>
</template>

<script>
	export default {
		name:"addtcontent",
		props: {
    		teas:{
    			type:Object,	
    			default: function() {
					return null
				}
    		},
    		title:{
    			type:String,	
    		},
    	},
		data() {
			//长度控制
			const lenPass = (rule, str, callback) => {
			  if(str.length>rule.length){
			  	 callback(new Error('字符串长度在1-'+rule.length+'之间！'));
			  }
			  return callback();
			};
				//正整数控制
			const zzsPass1 = (rule, value, callback) => {
			    let reg = /^\+?[1-9][0-9]*$/; 
				if(!reg.test(value)){
				    callback(new Error('请输入正整数！'));
				}else{
				  	return callback();
				}
			};
			return {
				ruleValidate: {
					dlzh: [
					    {required: true, message: '此项为必填项！', trigger: 'blur'},
						{length:20,validator:lenPass,trigger:'blur'},
					], 
		            name: [
		               {required: true, message: '此项为必填项！', trigger: 'blur'},
		               {length:20,validator:lenPass,trigger:'blur'}
		            ],
					wstate: [
					   {required: true, message: '此项为必选项！', trigger: 'blur'},
					   {length:20,validator:lenPass,trigger:'blur'}
					],
					sex: [
					   {required: true, message: '此项为必填项！', trigger: 'blur'},
					   {length:20,validator:lenPass,trigger:'blur'}
					]
		      },
                modal0:false,
                params:{
					usid:'',
					dlzh:'',
					name:'', 
					wstate:'', 
					sex:'', 
					zw:'',
					nj:'',
					bj:'',
					year:''
				},
				rxn:false
			}
		},
		components: {
		},
		methods: {
			addsave:function(){
				if(this.params.wstate=="1"){
					var nj=this.params.nj;
					if(nj==""){
						this.$Modal.error({
						    title: "错误",
						    content:"学生账号必须输入年级"
						});	
					}
					
					var bj=this.params.bj;
					if(bj==""){
						this.$Modal.error({
						    title: "错误",
						    content:"学生账号必须输入班级"
						});	
					}
					
					var year=this.params.year;
					if(year==""){
						this.$Modal.error({
						    title: "错误",
						    content:"学生账号必须输入入学年"
						});	
					}
					
				}
				
				this.$refs.params.validate((valid) => {
					if (valid){
						const params={...this.params};
						this.$emit("addsave",params);
                    }
               })
	        }, 
			
            closeModal(){
	      	    this.modal0 = false;
				this.$emit("closeModal");
	      	    this.resetpar();
	        },
	        resetpar(){
	        	this.params={
	        		usid:'',
	        		dlzh:'',
	        		name:'', 
	        		wstate:'', 
	        		sex:'', 
	        		zw:'',
	        		nj:'',
	        		bj:'',
	        		year:''
				};
	        },
			
			wstatechange(){
				if(this.params.wstate=="1"){
					this.rxn=true;
				}else{
					this.rxn=false;
					this.params.year="";
				}
				
			}
	        
		},
		mounted() {
		
  			
		},
		watch:{
			modal0(news,olds){
				if(!news){
					 this.resetpar();
				}else{
					this.params=this.teas;
				}
			}
		},
		computed: {
			
		}
		
	}
</script>

<style scoped="scoped">
	
</style>



